var http = require('http'),
    qs = require('qs'),
    send = function (jsono, cb) {
        var queryRes = '';
        var parameter = qs.stringify(jsono),
            options = {
                host: 'tools.wosoiot.com',
                port: 8080,
                method: 'get',
                path: `/interfaces/v1/card/info.action?amount=admin@103978&key=62de108aa5b4ab6ef098ab33e5713623&iccid=${jsono.iccid}`,
                headers: {
                    'Content-Type': 'application/x-www-form-urlencoded',
                    'Content-Length': parameter.length
                }
            },
            request = http.request(
                options, function (response) {
                    response.setEncoding('utf8');
                    response.on('data', function (chunk) {
                        queryRes += chunk;
                    }).on('end', function (chunk) {
                        try {
                            cb.call(null, null, queryRes);
                        } catch (e) {
                            cb.call(null, JSON.stringify({"error": true}));
                        }
                    });
                });
        request.on('error', function (e) {
            var error = JSON.stringify({"error": true, "message": e.code});
            cb.call(this, error);
        });
        request.write(parameter);
        request.end();
    };
exports.send = send;
